home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1731 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.0 KB  |  116 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!xanthas
  3. From: xanthas@netcom.com (Mike Day)
  4. Subject: Watcom C/C++ Gurus:  Please Help.
  5. Message-ID: <xanthasDL2rIv.H8x@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. Date: Fri, 12 Jan 1996 15:40:05 GMT
  9. Sender: xanthas@netcom19.netcom.com
  10.  
  11.  
  12. Thanks for reading.
  13.  
  14. For reference:  I am using Watcom C/C++ version 10.0, in DOS, in 
  15. protected mode via DOS4GW.  I have years of experience in both C/C++ and 
  16. Assembly.  I have experience with hooking and handling interrupts but not 
  17. in protected mode.
  18.  
  19.  
  20. I am trying to write a program that acts like a TSR.  It hooks some
  21. interrupts to enable a hot key to popup a subprogram, then uses spawnl() to
  22. run command.com.  When command.com exits, it unhooks the interrupts.  So,
  23. its like a fake popup TSR.
  24.  
  25. Within this fake popup TSR I must hook the following interrupts:
  26.  
  27.     Description:    Vector:
  28.  
  29.     Timer         0x08
  30.     Keyboard    0x09
  31.     Video        0x10
  32.     Disk        0x13
  33.     Idle        0x28
  34.     CtrlC        0x1B
  35.     CtrlBreak    0x23
  36.     CritError    0x24
  37.  
  38. My hook functions are declared like this:
  39.  
  40.     void __interrupt __far Timer();
  41.     etc..etc..
  42.  
  43. After compiling a test program and viewing its assembly language in the 
  44. debugger, I discovered the following...
  45.  
  46. At the beginning of each of my hook functions, Watcom produces this code:
  47.  
  48.     pushad
  49.     push    ds
  50.     push    es
  51.     push    fs
  52.     push    gs
  53.     mov    ebp,esp
  54.     sub    esp,00000000 ; number of bytes needed for local vars
  55.     cld
  56.     call    __GETDS
  57.  
  58. At the end of each of my hook functions, Watcom produces the following code:
  59.  
  60.     mov    esp,ebp
  61.     pop    gs
  62.     pop    fs
  63.     pop    es
  64.     pop    ds
  65.     popad
  66.     iretd
  67.  
  68. This causes problems when I hook the Disk and Video interrupts.  The 
  69. normal implementation of those interrupts causes certain registers and 
  70. flags to be changed upon exit.  With Watcom's above code, I cannot hook 
  71. those interrupts properly.
  72.  
  73. In real mode, in a previous (and similar) project, my Disk function was 
  74. looked like this in assembly:
  75.  
  76.     Disk PROC
  77.         ; Indicate we're inside disk interrupt
  78.         mov    cs:disk.active,1
  79.  
  80.         ; Fake call to old interrupt    
  81.         pushf
  82.         call    disk.old
  83.  
  84.         ; Indicate we're outside disk interrupt
  85.         mov    cs:disk.active,0
  86.  
  87.         ; Fake IRET without changing flags
  88.         sti
  89.         ret 2
  90.     Disk ENDP
  91.  
  92. (BTW, the above code worked perfectly.  The reason I did this is to have 
  93. a way to prevent the hotkey from activating my popup program during disk 
  94. activity.)
  95.  
  96. Now I need to do the equivalent in Watcom C/C++, in protected mode.
  97.  
  98. How do I do this?  Any ideas?  Have you done anything similar?
  99.  
  100. I've tried to get around the problem a couple ways...  First, I tried 
  101. using auxilary pragmas to negate Watcom's code.  The only problem then 
  102. is, I lose the data segment, and I can't get it back using "call 
  103. __GETDS", because the compiler says its undefined.  Second, I tried 
  104. writing external assembly procedures rather than C ones, but I still had 
  105. the data segment problem (DGROUP was undefined).
  106.  
  107. Thanks for reading and any/all help.
  108. --
  109. Mike Day
  110. please post answers and/or email them to:
  111.     xanthas@netcom.com
  112.         or
  113.     omni@pe.net
  114.  
  115.  
  116.